import {request, post, get} from "@/utils/request";
import ApiResult from "@/api/base/ApiResult";
import {
  ILoginByQRCodeData,
  IQRCodeData,
  IQRCodeRes,
  IQRCodeStatusData,
  IQRCodeStatusRes,
  ISelectAccountsData, ISelectAccountsRes, IUpdatePasswordData,
  templateAccount
} from "@/api/modules/login";

/**
 * 获取验证码图片接口
 * @returns {promise} Promise
 */
export async function getVerifyImage() {
  const rs: ApiResult<any> = await post(
    `permission/verification/sendImageCode`
  );
  return rs;
}

/**
 * 账号密码登录接口
 * @returns {promise} Promise
 */
export async function login(data: templateAccount) {
  const rs: ApiResult<any> = await post(
    "permission/login/merchant/login",
    data
  );
  return rs;
}

/**
 * 账号密码登录接口
 * @returns {promise} Promise
 */
export async function logout() {
  const rs: ApiResult<any> = await post("permission/login/merchant/signOut");
  return rs;
}

/**
 * 系统上传的配置
 * @returns {promise} Promise
 */
export async function getUploadConfig() {
  const rs: ApiResult<any> = await request("merchant/file/getConfig", {});
  return rs;
}

/**
 * 获取二维码状态
 * @param data
 * @param data.qrCode 二维码内容
 * @param data.tag 标记，需要在整个登陆过程中传递
 */
export async function getQRCodeStatus(data: IQRCodeStatusData): Promise<ApiResult<IQRCodeStatusRes>> {
  return post('permission/login/qr/getQRCodeStatus', data)
}

/**
 * 生成二维码
 * @param {IQRCodeData} data
 */
export async function getQRCode(data: IQRCodeData): Promise<ApiResult<IQRCodeRes>> {
  return post('permission/login/qr/getQRCode', data)
}

/**
 * 选择账号
 * @param data
 */
export async function selectAccounts(data: ISelectAccountsData): Promise<ApiResult<ISelectAccountsRes>> {
  return post('permission/login/qr/selectAccounts', data, {isHidenNotice: true})
}

/**
 * 通过QRCode登录
 * @param data
 */
export async function loginByQRCode(data: ILoginByQRCodeData): Promise<ApiResult<any>> {
  return post('permission/login/qr/loginByQRCode', data)
}

/**
 * 修改密码
 */
export function updatePassword(data: IUpdatePasswordData): Promise<ApiResult<any>> {
  return request('merchant/admin/updatePassword', data)
}
/**
 * 根据token获取用户信息
 */
 export function getTokenUser(data: any): Promise<ApiResult<any>> {
  return request('merchant/merchantLog/getTokenUser', data)
}